package com.wlstock.funi.widget;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.wlstock.funi.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by admin on 16/6/25.
 */
public class DialogContentView {
    private static DialogContentView ourInstance = new DialogContentView();

    public static DialogContentView getInstance() {
        return ourInstance;
    }

    private DialogContentView() {
    }

    public View listView(Context mContext, List<? extends  Map<String, ?>> datas, String[] keyValue,boolean isEdit){
        LinearLayout contain = new LinearLayout(mContext);
        LinearLayout.LayoutParams containParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 400);
        contain.setLayoutParams(containParams);

        ListView lv = new ListView(mContext);
        SimpleAdapter adapter = null;
        if (!isEdit){
            adapter = new SimpleAdapter(mContext, datas, R.layout.pop_list_item_unedit_key_value,keyValue, new int[]{R.id.tv_item_key,R.id.tv_item_value});
        }else{
            adapter = new SimpleAdapter(mContext, datas, R.layout.pop_list_item_edit_key_value,keyValue, new int[]{R.id.tv_item_key,R.id.ed_item_value});
        }
        lv.setAdapter(adapter);


        contain.addView(lv);
        return contain;
    }

    public View listView(Context mContext, Map<String, ?> datas,boolean isEdit){
        List<HashMap<String, String>> listDatas = new ArrayList<HashMap<String, String>>();
        for(String key: datas.keySet()){
            HashMap<String ,String> map = new HashMap<String, String>();
            map.put("KEY",key);
            map.put("VALUE", (String) datas.get(key));
            listDatas.add(map);
        }
        LinearLayout contain = new LinearLayout(mContext);
        LinearLayout.LayoutParams containParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 400);
        contain.setLayoutParams(containParams);

        ListView lv = new ListView(mContext);
        SimpleAdapter adapter = null;
        if (!isEdit){
            adapter = new SimpleAdapter(mContext, listDatas, R.layout.pop_list_item_unedit_key_value,new String[]{"KEY","VALUE"}, new int[]{R.id.tv_item_key,R.id.tv_item_value});
        }else{
            adapter = new SimpleAdapter(mContext, listDatas, R.layout.pop_list_item_edit_key_value,new String[]{"KEY","VALUE"}, new int[]{R.id.tv_item_key,R.id.ed_item_value});
        }
        lv.setAdapter(adapter);

        contain.addView(lv);
        return contain;
    }

//    public View listView(final Context mContext, final Map<String, ?> datas, boolean isEdit){
//        LinearLayout contain = new LinearLayout(mContext);
//        LinearLayout.LayoutParams containParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 400);
//        contain.setLayoutParams(containParams);
//        ListView lv = new ListView(mContext);
//        BaseAdapter adapter = new BaseAdapter() {
//            @Override
//            public int getCount() {
//                return datas.keySet().size();
//            }
//
//            @Override
//            public Object getItem(int position) {
//                return datas.
//            }
//
//            @Override
//            public long getItemId(int position) {
//                return position;
//            }
//
//            @Override
//            public View getView(int position, View convertView, ViewGroup parent) {
//                LayoutInflater.from(mContext).inflate(R.layout.pop_list_item_edit_key_value,)
//                return null;
//            }
//        };
//
//    }


}
